from sqlalchemy import Column, String, create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

# 创建对象基类
Base = declarative_base()


# 定义user对象
class User(Base):
    __tablename__ = 'user'

    id = Column(String(20), primary_key=True)
    name = Column(String(20))


engine = create_engine('mysql+mysqlconnector://root:weixin123@localhost:3306/company')
DBSession = sessionmaker(bind=engine)

session = DBSession()
new_User = User(id='3', name='marry')
session.add(new_User)
session.commit()
session.close()

session01 = DBSession()
user = session01.query(User).filter(User.id == '5').one()
user01 = session01.query(User).filter(User.id == '1').one()
print('name:', user.name)
print('name01:', user01.name)
session01.close()
